home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / xinetd / xinetd.2.0.6 / sconf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-22  |  7.4 KB  |  285 lines

  1. /*
  2.  * (c) Copyright 1992 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7. static char RCSid[] = "$Id: sconf.c,v 5.1 1992/11/01 00:01:21 panos Exp $" ;
  8.  
  9. #include "fsma.h"
  10. #include "sio.h"
  11.  
  12. #include "defs.h"
  13. #include "attr.h"
  14. #include "sconf.h"
  15. #include "state.h"
  16. #include "addr.h"
  17.  
  18. #define FREE( x )                if ( x )                   \
  19.                                  {                          \
  20.                                     free( (char *) x ) ;    \
  21.                                     x = NULL ;              \
  22.                                  }
  23.  
  24. extern struct name_value success_log_options[] ;
  25. extern struct name_value failure_log_options[] ;
  26. extern struct name_value service_types[] ;
  27. extern struct name_value service_flags[] ;
  28. extern struct name_value socket_types[] ;
  29. extern struct name_value syslog_facilities[] ;
  30. extern struct name_value syslog_levels[] ;
  31.  
  32. void tabprint() ;
  33.  
  34.  
  35. /*
  36.  * Print info about service sp to file descriptor fd
  37.  */
  38. void sconf_dump( scp, fd, tab_level, is_defaults )
  39.     register struct service_config *scp ;
  40.     register int fd ;
  41.     int tab_level ;
  42.     bool_int is_defaults ;
  43. {
  44.     register struct name_value *nvp ;
  45.     register unsigned u ;
  46.     register char **pp ;
  47.     void dump_intervals() ;
  48.     void dump_log_data() ;
  49.     struct name_value *nv_find_name() ;
  50.  
  51.     if ( is_defaults )
  52.         tabprint( fd, tab_level, "Service defaults\n" ) ;
  53.     else
  54.         tabprint( fd, tab_level, "Service configuration data\n" ) ;
  55.  
  56.     if ( ! is_defaults )
  57.     {
  58.         tabprint( fd, tab_level+1, "id = %s\n", scp->id ) ;
  59.  
  60.         tabprint( fd, tab_level+1, "flags =" ) ;
  61.         for ( nvp = &service_flags[ 0 ] ; nvp->name != NULL ; nvp++ )
  62.             if ( M_IS_SET( scp->flags, nvp->value ) )
  63.                 Sprint( fd, " %s", nvp->name ) ;
  64.         Sputchar( fd, '\n' ) ;
  65.  
  66.         tabprint( fd, tab_level+1, "type =" ) ;
  67.         for ( nvp = &service_types[ 0 ] ; nvp->name != NULL ; nvp++ )
  68.             if ( M_IS_SET( scp->type, nvp->value ) )
  69.                 Sprint( fd, " %s", nvp->name ) ;
  70.         Sputchar( fd, '\n' ) ;
  71.  
  72.         tabprint( fd, tab_level+1, "socket_type = %s\n",
  73.             ( nvp = nv_find_name( socket_types, scp->socket_type ) )
  74.                 ? nvp->name : "BAD_SOCKET_TYPE" ) ;
  75.  
  76.         if ( SPECIFIED( scp, A_PORT ) )
  77.             tabprint( fd, tab_level+1, "port = %d\n", scp->port ) ;
  78.  
  79.         tabprint( fd, tab_level+1, "Protocol (name,number) = (%s,%d)\n",
  80.                 scp->protocol.name, scp->protocol.value ) ;
  81.     }
  82.  
  83.     if ( SPECIFIED( scp, A_INSTANCES ) )
  84.         if ( scp->instances == UNLIMITED )
  85.             tabprint( fd, tab_level+1, "Instances = UNLIMITED\n" ) ;
  86.         else
  87.             tabprint( fd, tab_level+1, "Instances = %d\n", scp->instances ) ;
  88.  
  89.     if ( ! is_defaults )
  90.     {
  91.         if ( ! IS_INTERNAL( scp ) )
  92.         {
  93.             tabprint( fd, tab_level+1, "Server = %s\n", scp->server ) ;
  94.             tabprint( fd, tab_level+1, "Server argv =" ) ;
  95.             for ( pp = scp->server_argv ; *pp ; pp++ )
  96.                 Sprint( fd, " %s", *pp ) ;
  97.             Sputchar( fd, '\n' ) ;
  98.         } 
  99.  
  100.         if ( IS_RPC( scp ) )
  101.         {
  102.             struct rpc_data *rdp = &scp->rd ;
  103.  
  104.             tabprint( fd, tab_level+1, "RPC data\n" ) ;
  105.             tabprint( fd, tab_level+2,
  106.                                     "program number = %ld\n", rdp->program_number ) ;
  107.             tabprint( fd, tab_level+2, "rpc_version = " ) ;
  108.             if ( rdp->min_version == rdp->max_version )
  109.                 Sprint( fd, "%ld\n", rdp->min_version ) ;
  110.             else
  111.                 Sprint( fd, "%ld-%ld\n", rdp->min_version, rdp->max_version ) ;
  112.         }
  113.  
  114.         if ( SPECIFIED( scp, A_ACCESS_TIMES ) )
  115.         {
  116.             tabprint( fd, tab_level+1, "Access times =" ) ;
  117.             dump_intervals( scp->access_times, fd ) ;
  118.             Sputchar ( fd, '\n' ) ;
  119.         }
  120.     }
  121.  
  122.     if ( SPECIFIED( scp, A_ONLY_FROM ) )
  123.     {
  124.         tabprint( fd, tab_level+1, "Only from: " ) ;
  125.         addrlist_dump( scp->only_from, fd ) ;
  126.         Sputchar( fd, '\n' ) ;
  127.     }
  128.  
  129.     if ( SPECIFIED( scp, A_NO_ACCESS ) )
  130.     {
  131.         tabprint( fd, tab_level+1, "No access: " ) ;
  132.         addrlist_dump( scp->no_access, fd ) ;
  133.         Sputchar( fd, '\n' ) ;
  134.     }
  135.     
  136.     dump_log_data( fd, scp, tab_level+1 ) ;
  137.  
  138.     if ( SPECIFIED( scp, A_PASSENV ) )
  139.     {
  140.         tabprint( fd, tab_level+1, "Passenv =" ) ;
  141.         for ( u = 0 ; u < pset_count( scp->passenv ) ; u++ )
  142.             Sprint( fd, " %s", (char *) pset_pointer( scp->passenv, u ) ) ;
  143.         Sputchar ( fd, '\n' ) ;
  144.     }
  145.  
  146.     if ( ! is_defaults )
  147.         if ( SPECIFIED( scp, A_ENV ) )
  148.         {
  149.             tabprint( fd, tab_level+1, "Environment additions:\n" ) ;
  150.             for ( u = 0 ; u < pset_count( scp->env ) ; u++ )
  151.                 tabprint( fd, tab_level+2,
  152.                         "%s\n", (char *) pset_pointer( scp->env, u ) ) ;
  153.         }
  154.     
  155.     if ( ENV( scp )->env_type == CUSTOM_ENV )
  156.     {
  157.         tabprint( fd, tab_level+1, "Environment strings:\n" ) ;
  158.         for ( pp = env_getvars( ENV( scp )->env ) ; *pp ; pp++ )
  159.             tabprint( fd, tab_level+2, "%s\n", *pp ) ;
  160.     }
  161. }
  162.  
  163.  
  164. PRIVATE void dump_log_data( fd, scp, tab_level )
  165.     int fd ;
  166.     register struct service_config *scp ;
  167.     int tab_level ;
  168. {
  169.     register struct log *lp = LOG( scp ) ;
  170.     register struct filelog *flp ;
  171.     register struct name_value *nvp, *nvp2 ;
  172.     int i ;
  173.  
  174.     switch ( lp->log_type )
  175.     {
  176.         case L_NONE:
  177.             tabprint( fd, tab_level, "No logging\n" ) ;
  178.             return ;
  179.  
  180.         case L_COMMON_FILE:
  181.             tabprint( fd, tab_level, "Logging to common log file\n" ) ;
  182.             break ;
  183.  
  184.         case L_FILE:
  185.             flp = FILELOG( lp ) ;
  186.             tabprint( fd, tab_level, "Logging to file: %s", flp->filename ) ;
  187.  
  188.             if ( FILELOG_SIZE_CONTROL( flp ) )
  189.                 Sprint( fd, " (soft=%d hard=%d)\n",
  190.                                 flp->soft_limit, flp->hard_limit ) ;
  191.             else
  192.                 Sprint( fd, " (no limits)\n" ) ;
  193.             break ;
  194.         
  195.         case L_SYSLOG:
  196.             tabprint( fd, tab_level,
  197.                 "Logging to syslog. Facility = %s, level = %s\n",
  198.                 ( nvp = nv_find_name( syslog_facilities, SYSLOG( lp )->facility ) )
  199.                         ? nvp->name : "BAD FACILITY",
  200.                 ( nvp2 = nv_find_name( syslog_levels, SYSLOG( lp )->level ) )
  201.                         ? nvp2->name : "BAD LEVEL" ) ;
  202.             break ;
  203.     }
  204.  
  205.     tabprint( fd, tab_level, "Log_on_success flags =" ) ;
  206.     for ( i = 0 ; success_log_options[ i ].name != NULL ; i++ )
  207.         if ( M_IS_SET( scp->log_on_success, success_log_options[ i ].value ) )
  208.             Sprint( fd, " %s", success_log_options[ i ].name ) ;
  209.     Sputchar( fd, '\n' ) ;
  210.  
  211.     tabprint( fd, tab_level, "Log_on_failure flags =" ) ;
  212.     for ( i = 0 ; failure_log_options[ i ].name != NULL ; i++ )
  213.         if ( M_IS_SET( scp->log_on_failure, failure_log_options[ i ].value ) )
  214.             Sprint( fd, " %s", failure_log_options[ i ].name ) ;
  215.     Sputchar( fd, '\n' ) ;
  216. }
  217.  
  218.  
  219.  
  220. /*
  221.  * Free all malloc'ed memory for the specified service
  222.  */
  223. void sconf_free( scp )
  224.    register struct service_config *scp ;
  225. {
  226.     void free_intervals() ;
  227.     void release_pset() ;
  228.  
  229.    FREE( scp->name ) ;
  230.    FREE( scp->id ) ;
  231.    FREE( scp->protocol.name ) ;
  232.    FREE( scp->server ) ;
  233.    if ( scp->server_argv )
  234.    {
  235.       register char **pp ;
  236.  
  237.         /*
  238.          * argv[ 0 ] is a special case because it may not have been allocated yet
  239.          */
  240.         if ( scp->server_argv[ 0 ] != NULL)
  241.             free( scp->server_argv[ 0 ] ) ;
  242.       for ( pp = &scp->server_argv[ 1 ] ; *pp != NULL ; pp++ )
  243.          free( *pp ) ;
  244.       free( (char *) scp->server_argv ) ;
  245.    }
  246.    FREE( FILELOG( LOG( scp ) )->filename ) ;
  247.  
  248.     if ( scp->access_times != NULL )
  249.     {
  250.         free_intervals( scp->access_times ) ;
  251.         pset_destroy( scp->access_times ) ;
  252.     }
  253.  
  254.     if ( scp->only_from != NULL )
  255.     {
  256.         addrlist_free( scp->only_from ) ;
  257.         pset_destroy( scp->only_from ) ;
  258.     }
  259.  
  260.     if ( scp->no_access != NULL )
  261.     {
  262.         addrlist_free( scp->no_access ) ;
  263.         pset_destroy( scp->no_access ) ;
  264.     }
  265.  
  266.    if ( scp->env != NULL )
  267.         release_pset( scp->env, (fsma_h) NULL ) ;
  268.     if ( scp->passenv != NULL )
  269.         release_pset( scp->passenv, (fsma_h) NULL ) ;
  270.     if ( scp->environment.env_type == CUSTOM_ENV && ENV( scp )->env != ENV_NULL )
  271.         env_destroy( ENV( scp )->env ) ;
  272. }
  273.  
  274.  
  275. PRIVATE void release_pset( pset, allocator )
  276.     pset_h pset ;
  277.     fsma_h allocator ;
  278. {
  279.     void free_pset() ;
  280.  
  281.     free_pset( pset, allocator ) ;
  282.     pset_destroy( pset ) ;
  283. }
  284.  
  285.